#!/usr/bin/make -f

# Debian 'rules' file for the Hydrogen Drum Machine.
#
# To make the build more verbose, uncomment the following line:
#export DH_VERBOSE=1
#
# To enable scons PARALLEL BUILDS (e.g. -j 4), run like this:
#     $ H2_PARALLEL=4 dpkg-buildpackage -rfakeroot
# ...or uncomment the following line:
H2_PARALLEL=4
# ...or invoke dpkg-buildpackage like this:
#     $ dpkg-buildpackage -j4 -rfakeroot
# However, the -j4 here will run more than gcc in parallel.

# Check for parallel builds.
# NUMJOBS script goodie courtesy of http://lists.debian.org/debian-policy/2007/08/msg00005.html

NUMJOBS=$(patsubst parallel=%,%,$(filter parallel=%,$(subst $(,), ,$(DEB_BUILD_OPTIONS))))
ifneq ("$(H2_PARALLEL)","")
	H2_PARALLEL_BUILDS=-j $(H2_PARALLEL)
else
	ifneq ("$(NUMJOBS)","")
		H2_PARALLEL_BUILDS=-j $(NUMJOBS)
	endif
endif


configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	mkdir ../builddebian
	cd ../builddebian; cmake .. -DCMAKE_INSTALL_PREFIX=/usr
	
	touch configure-stamp


build: build-stamp
build-stamp: configure-stamp
	dh_testdir

        # Add here commands to compile the package.
	cd ../builddebian; $(MAKE) $(H2_PARALLEL_BUILDS)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	-find . -name '*.py[co]' | xargs rm -f

	# Add here commands to clean up after the build process.
	rm -rf ../builddebian;
	dh_clean


install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	mkdir -p $(CURDIR)/debian/hydrogen/usr/bin

	cd ../builddebian; $(MAKE) install DESTDIR=../linux/debian/hydrogen
	#remove not used .git dirs 
	find $(CURDIR)/debian/hydrogen/ -name '.git' | xargs rm -rf 

docs:


docs_install:



# Build architecture-independent files here.
binary-indep: build install docs docs_install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installchangelogs
	dh_installdocs
	dh_installman
	dh_link
	dh_compress
	dh_compress -X.py
	dh_fixperms
	dh_strip
	#dh_python
	dh_makeshlibs
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb




binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
